
#include <BImage>
#include <BImage>
#include <BFont>

#include <BTableItem>
#include "member_BTableItem.h"

using namespace BWE;

#define member					(*(member_BTableItem*)_ptr)
#define member_allocate()		_ptr = new member_BTableItem(this)
#define member_release()		delete (member_BTableItem*)_ptr

BTableItem::BTableItem()
{
	member_allocate();
}
BTableItem::BTableItem(const BString& text)
{
	member_allocate();
	setText(text);
}
BTableItem::BTableItem(Graph graph, const BString& text, Form form)
{
	member_allocate();
	setGraph(graph);
	setText(text);
	setForm(form);
}
BTableItem::BTableItem(BIcon* icon, const BString& text, Form form)
{
	member_allocate();
	setIcon(icon);
	setText(text);
	setForm(form);
}
BTableItem::BTableItem(BImage* image, const BString& text, Form form)
{
	member_allocate();
	setImage(image);
	setText(text);
	setForm(form);
}
BTableItem::BTableItem(BWidget* widget, const BString& text, Form form)
{
	member_allocate();
	setWidget(widget);
	setText(text);
	setForm(form);
}
BTableItem::~BTableItem()
{
	member_release();
}

void BTableItem::setForm(Form form)
{
	if (member.ia_form != form)
	{
		member.ia_form = form;
		member.dirty = true;
		member.dirtyCell();
	}
}
Form BTableItem::form() const
{
	return member.ia_form;
}

void BTableItem::setAlign(Align align)
{
	if (member.ia_align != align)
	{
		member.ia_align = align;
		member.dirtyCell();
	}
}
Align BTableItem::align() const
{
	return member.ia_align;
}

void BTableItem::setLineFeed(bool lineFeed)
{
	if (member.lineFeed != lineFeed)
	{
		member.lineFeed = lineFeed;
		member.dirtyCell();
	}
}
bool BTableItem::lineFeed() const
{
	return member.lineFeed;
}

void BTableItem::setSelected(bool selected)
{
	if (member.selected != selected)
	{
		member.table->setItemSelected(this, selected);
	}
}
bool BTableItem::isSelected() const
{
	if (member.table)
		return table_member(member.table)->selectedItems.contain(this);
	return false;
}

void BTableItem::setColor(BByte r, BByte g, BByte b, BByte a)
{
	setColor(BColor(r, g, b, a));
}
void BTableItem::setColor(const BColor& color)
{
	if (member.color != color)
	{
		member.color = color;
		member.dirtyCell();
	}
}
const BColor& BTableItem::color() const
{
	return member.color;
}

void BTableItem::setGraph(Graph graph)
{
	if (member.graph != graph)
	{
		member.graph = graph;
		member.dirtyCell();
		member.dirty = true;
	}
}
Graph BTableItem::graph() const
{
	return member.graph;
}

void BTableItem::setImage(BImage* image)
{
	if (member.image != image)
	{
		member.image = image;
		member.dirtyCell();
		member.dirty = true;
	}
}
BImage* BTableItem::image() const
{
	return member.image;
}

void BTableItem::setIcon(BIcon* icon)
{
	if (member.icon != icon)
	{
		member.icon = icon;
		member.dirtyCell();
		member.dirty = true;
	}
}
BIcon* BTableItem::icon() const
{
	return member.icon;
}

void BTableItem::setIconSize(int width, int height)
{
	setIconSize(BSize(width, height));
}
void BTableItem::setIconSize(const BSize& iconSize)
{
	if (member.iconSize != iconSize)
	{
		member.iconSize = iconSize;
		member.dirtyCell();
	}
}
const BSize& BTableItem::iconSize() const
{
	return member.iconSize;
}

void BTableItem::setText(const BString& text)
{
	if (member.block.text != text)
	{
		member.block.text = text;
		member.block.reset();
		member.dirtyCell();
		member.dirty = true;
	}
}
const BString& BTableItem::text() const
{
	return member.block.text;
}

void BTableItem::setWidget(BWidget* widget)
{
	if (member.widget != widget)
	{
		if (member.table && member.widget)
		{
			member.table->removeChild(member.widget);
			member.widget = 0;
		}
		member.widget = widget;
		if (member.table && member.widget)
		{
			member.table->addChild(member.widget);
			member.widget->setFloating(false);
		}
		member.dirty = true;
		member.dirtyCell();
	}
}
BWidget* BTableItem::widget()
{
	return member.widget;
}
const BWidget* BTableItem::widget() const
{
	return member.widget;
}

void BTableItem::setFormat(BTextFormat* format)
{
	if (member.block.textFormat != format)
	{
		member.block.textFormat = format;
		member.dirtyCell();
	}
}
BTextFormat* BTableItem::format()
{
	return member.block.textFormat;
}
const BTextFormat* BTableItem::format() const
{
	return member.block.textFormat;
}

int BTableItem::row() const
{
	if (member.table)
	{
		return member.row;
	}
	return -1;
}
int BTableItem::column() const
{
	if (member.table)
	{
		return member.column;
	}
	return -1;
}

const BRect& BTableItem::rect() const
{
	return member.rect;
}
const BRect& BTableItem::iconRect() const
{
	return member.ia_imageRect;
}
const BRect& BTableItem::textRect() const
{
	return member.ia_textRect;
}
const BRect& BTableItem::textArea() const
{
	return member.ia_textArea;
}

BTableWidget* BTableItem::tableWidget()
{
	return member.table;
}
const BTableWidget* BTableItem::tableWidget() const
{
	return member.table;
}

